package cn.buyclss.backend.controller.shop;

import cn.buyclss.backend.entity.support.RespResult;
import cn.buyclss.backend.service.shop.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: Cecurio
 * @create: 2019-03-18 16:45
 **/
@RestController
@RequestMapping("/order")
@Api(value = "订单管理-商家", description = "订单管理-商家")
public class OrderController {
    @Autowired
    OrderService orderService;

    @GetMapping("/my")
    @RequiresRoles("shop")
    @ApiOperation(value = "查看我店铺的所有的订单", notes = "查看我店铺的所有的订单. 操作者角色：shop")
    @ApiImplicitParams({
        @ApiImplicitParam(paramType = "header", name = "Authorization", value = "用户凭证", required = true),
        @ApiImplicitParam(paramType = "query", name = "pageIndex", value = "分页：第几页，默认为1", required = true),
        @ApiImplicitParam(paramType = "query", name = "pageSize", value = "分页：每页多少条，默认为10", required = true)
    })
    public RespResult getMyOrders(@RequestParam(value = "pageIndex", defaultValue = "1") Integer pageIndex,
                                  @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        return orderService.getMyOrders(pageIndex, pageSize);
    }


    @GetMapping("/getOrderDetailById")
    @RequiresAuthentication
    @ApiOperation(value = "查看订单的详细信息", notes = "查看订单的详细信息. ")
    @ApiImplicitParams({
        @ApiImplicitParam(paramType = "header", name = "Authorization", value = "用户凭证", required = true),
        @ApiImplicitParam(paramType = "query", name = "orderId", value = "订单ID", required = true)
    })
    public RespResult getOrderDetailById(@RequestParam(value = "orderId") Integer orderId) {
        return orderService.getOrderDetailById(orderId);
    }

}
